<template>
  <div class="wrap">
    <h1>乐享运动80+</h1>
    <ul class="sports-con" :class="{ nomore: !isMore }">
      <li
        class="sports-item"
        v-for="(item, index) in categoryList"
        :key="index"
        @click="goToSearch"

      >
        <img :src="item.menuThumbnail" alt="" />
        <span>{{ item.displayName }}</span>
      </li>
    </ul>
    <button @click="checkAllData" class="checkAll" v-if="!isMore">查看所有运动</button>
    <button v-else class="reback" @click="checkAllData">收起</button>

    <div class="benefits-img">
      <img src="./images/1.jpg" alt="">
      <img src="./images/2.jpg" alt="">
      <img src="./images/3.jpg" alt="">
      <img src="./images/4.jpg" alt="">
    </div>

  </div>
</template>

<script>
export default {
  data() {
    return {
      categoryList: [],
      isMore: false,
    };
  },
  mounted() {
    this.getCategoryList();
  },
  methods: {
    async getCategoryList() {
      let result = await this.$API.reqCategoryList();
      if(result.code === 200) {
         this.categoryList = result.data
      }
    },
    checkAllData() {
      this.isMore = !this.isMore;
    },
    goToSearch() {
      this.$router.push({
        name: 'search'
      }) 
    }
  },
};
</script>

<style lang="less" scoped>
.wrap {
  width: 1200px;
  margin: 40px auto;
  h1 {
    color: #1a2a34;
    font-size: 42px;
    font-style: normal;
    vertical-align: top;
    text-align: center;
    margin-bottom: 20px;
  }
  .sports-con {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-evenly;
    width: 100%;
    &.nomore {
      height: 180px;
      overflow: hidden;
    }
    .sports-item {
      cursor: pointer;
      width: 17%;
      height: 78px;
      display: flex;
      border-radius: 8px 8px 24px 8px;
      box-shadow: 2px 2px 4px 0 rgb(0 83 125 / 10%);
      margin-bottom: 15px;
      img {
        width: 75px;
        height: 75px;
      }
      span {
        line-height: 75px;
        margin-left: 20px;
      }
    }
  }
  .checkAll,.reback {
    position: relative;
    left: 50%;
    transform: translateX(-50%);
    border: none;
    outline: none;
    width: 400px;
    margin: 0 auto;
    height: 48px;
    font-size: 14px;
    font-weight: bold;
    background-color: #007dbc;
    color: #fff;
    text-align: center;
    line-height: 48px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.35s;
  }
  .benefits-img {
    width: 100%;
    height: 0;
    margin-top: 40px;
    padding-bottom: 200px;
    border-radius: 16px;
    display: flex;
    justify-content: space-evenly;
    img {
      width: 25%;
      margin-right: 15px;
      height: 150px;
    }
}
}
</style>